import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'index.dart';

class FadeTabbarPage extends GetView<FadeTabbarController> {
  const FadeTabbarPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    var state = controller.state;
    return Column(
      children: [
        TabBar(
            controller: state.tbCtrl,
            unselectedLabelColor: const Color(0xff999999),
            labelColor: Colors.blue,
            indicatorSize: TabBarIndicatorSize.label,
            tabs: state.tabTitles
                .asMap()
                .map((key, value) => MapEntry(
                    key,
                    Tab(
                      child: Text(value),
                    )))
                .values
                .toList()),
        Expanded(
          child: TabBarView(
            controller: state.tbCtrl,
            children: [
              Container(
                color: Colors.amber,
              ),
              Container(
                color: Colors.brown,
              ),
              Container(
                color: Colors.pinkAccent,
              ),
            ],
          ),
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FadeTabbarController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("fade_tabbar")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
